from kivy.graphics import Color, Line
from kivy.properties import NumericProperty
from kivy.uix.label import Label


# 自定义Label
class LabelComm(Label):
    font_size = NumericProperty(18)  # 默认字体大小
    color = [0, 0, 0, 1]  # 默认颜色（黑色）

    # 默认大小
    default_height = 35

    def __init__(self, **kwargs):
        super(LabelComm, self).__init__(**kwargs)
        self.size_hint = (1, None)  # 禁用size_hint以使用size属性
        self.height = self.default_height
        self.halign = 'left'  # 水平居中
        self.valign = 'middle'  # 垂直居中

        # with self.canvas.before:
        #     # 设置边框
        #     Color(0, 0, 1, 1)
        #     self.border = Line(rectangle=(self.x, self.y, self.width, self.height), width=1)
        # self.bind(size=self.update_rect, pos=self.update_rect)

    def on_size(self, *args):
        self.text_size = self.size  # 更新文本区域大小

    # def update_rect(self, instance, *args):
    #     # 更新边框
    #     self.border.rectangle = (self.x, self.y, self.width, self.height)
